(function () {
  const elevator = document.querySelector('.xtx-elevator')
  const entry = document.querySelector('.xtx_entry')
  window.addEventListener('scroll', function () {
    const n = document.documentElement.scrollTop
   elevator.style.opacity = n>=entry.offsetTop? '1': 0
  })
  const backTop = document.querySelector('#backTop')
  backTop.addEventListener('click', function () {
      window.scrollTo(0,0)
  });
})();



(function () {
  const list = document.querySelector('.xtx-elevator-list')
  list.addEventListener('click', function (e) {
    if (e.target.tagName === 'A' && e.target.dataset.name) {
      document.querySelector('.xtx-elevator-list .active') && document.querySelector('.xtx-elevator-list .active').classList.remove('active')
      e.target.classList.add('active')
      const top = document.querySelector(`.xtx_goods_${e.target.dataset.name}`).offsetTop
        document.documentElement.scrollTop = top
    }
    
    window.addEventListener('scroll', function () {
      const news = document.querySelector('.xtx_goods_new').offsetTop
      const popular = document.querySelector('.xtx_goods_popular').offsetTop
      const brand = document.querySelector('.xtx_goods_brand').offsetTop
      const topic = document.querySelector('.xtx_goods_topic').offsetTop
      document.querySelector('.xtx-elevator-list .active') && document.querySelector('.xtx-elevator-list .active').classList.remove('active')
      const n = document.documentElement.scrollTop
      if (n >= news && n < popular) {
       document.querySelector('[data-name="new"]').classList.add('active')
      } else if (n >= popular && n < brand) {
       document.querySelector('[data-name="popular"]').classList.add('active')
      }else if (n >= brand && n < topic) {
        document.querySelector('[data-name="brand"]').classList.add('active')
      }else if (n >= topic) {
          document.querySelector('[data-name="topic"]').classList.add('active')
        }
    })
  });

})();